package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.TaskEmployee;
import com.kaishengit.util.db.DBHelp;
import com.kaishengit.util.db.RowMapper;

public class TaskEmployeeDao {
	DBHelp<TaskEmployee> db = new DBHelp<TaskEmployee>();
	public List<com.kaishengit.entity.TaskEmployee> findByGoalId(String id) {
		String sql = "SELECT t_task.id, `name`,`desc`,endtime,state,`level`,rate,goalid ,username FROM t_task ,t_employee WHERE T_task.employeeid =t_employee.id AND goalid=?";
		return db.executeQueryToList(sql, new TaskEmployeeRowMapper(), id);
	}
	private class TaskEmployeeRowMapper implements RowMapper<TaskEmployee>{
		public TaskEmployee mapRow(ResultSet rs) throws SQLException{
			TaskEmployee te = new TaskEmployee();
			te.setTaskid(rs.getString("id"));
			te.setTaskname(rs.getString("name"));
			te.setTaskdesc(rs.getString("desc"));
			te.setEndtime(rs.getString("endtime"));
			te.setState(rs.getString("state"));
			te.setLevel(rs.getString("level"));
			te.setTaskrate(rs.getDouble("rate"));
			te.setGoalid(rs.getString("goalid"));
			te.setUsername(rs.getString("username"));
			return te;
			
		}
	}
	public TaskEmployee findTaskById(String id) {
		String sql ="SELECT t_task.id,`name`,`desc`,endtime,state,`level`,rate,goalid,username FROM t_task,t_employee WHERE t_task.employeeid=t_employee.id AND t_task.id=?";
		return db.executeQueryToObject(sql, new TaskEmployeeRowMapper(), id);
	}
}
